package com.zackratos.toprouter

import com.zackratos.component1.Component1
import com.zackratos.component2.Component2
import com.zackratos.component2.Component2Operator
import com.zackratos.component3.Component3
import com.zackratos.component4.Component4

/**
 * @Author   : zhangwenchao
 * @Date     : 2020/12/29  9:23 PM
 * @Describe :
 */
class TopComponent2: Component2.Observable, Component1.Observer, Component3.Observer, Component4.Observer {

    private val observers: MutableSet<Component2.Observer> by lazy { HashSet<Component2.Observer>() }


    override fun subscribe(observer: Component2.Observer) {
        observers.add(observer)
    }


    override fun postClickTopButton(content: String?) {
        for (observer in observers) {
            observer.onTopButton2Click(content)
        }
    }

    override fun onTopButton1Click(content: String?) {
        Component2Operator.getInstance().updateTopText(content)
    }

    override fun onTopButton3Click(content: String?) {
        Component2Operator.getInstance().updateTopText(content)
    }

    override fun onTopButton4Click(content: String?) {
        Component2Operator.getInstance().updateTopText(content)
    }

}